//
//  WLTabBarViewController.swift
//  Created by Visitor on 2017/7/7.
//  Copyright © 2017年 万利. All rights reserved.
//

import UIKit

class WLTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        addChildViewControllers()
    }
    private func addChildViewControllers() {

//        let path = Bundle.main.path(forResource: "MainVCSettings.json", ofType: nil)
//        if let jsonPath = path{
//            let jsonData = NSData(contentsOfFile: jsonPath)
//            
//            do{
//                let dictArr = try JSONSerialization.jsonObject(with: jsonData! as Data, options: JSONSerialization.ReadingOptions.mutableContainers)
//               
//                for dict in dictArr as! [[String: String]]
//                {
//                    addChildViewController(childControllerName: dict["vcName"]!, title: dict["title"]!, imageName: dict["imageName"]!)
//                }
//                
//            }catch
//            {
                addChildViewController(childControllerName: "WLHomeViewController", title: "家庭防护", imageName: "tabbar_home")
                addChildViewController(childControllerName: "WLToolsViewController", title: "工具箱", imageName: "tabbar_message_center")
                addChildViewController(childControllerName: "WLFileViewController", title: "我", imageName: "tabbar_profile")
//            }
//        }
        
    }
    
    private func addChildViewController(childControllerName: String, title:String, imageName:String) {

        let ns = Bundle.main.infoDictionary!["CFBundleExecutable"] as! String
        let cls:AnyClass? = NSClassFromString(ns + "." + childControllerName)
        let vcCls = cls as! UIViewController.Type
        let vc = vcCls.init()
        
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
//        vc.title = title
        vc.tabBarItem.title = title
        
        let nav = UINavigationController(rootViewController: vc)
        nav.navigationBar.isTranslucent = false
        nav.navigationBar.barTintColor = TXBule
//        nav.addChildViewController(vc)
        addChildViewController(nav)
    }
}
